program test_05_skybox;

{*
Small demo for testing skyboxes, default is test, can be changed in paramstr 1
}

uses SysUtils, gl, glu, glut, opengls, skyboxes, debugs, keyboards, vectors, VUMaths;

var 
  SkyBox : TSkyBox;
  AngleH, AngleV : real;

procedure OnDisplay; cdecl;
begin
  // OpenGL soap
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glLoadIdentity;
  
  // keyboard pan (arrows or wasd)
  if KeyIsDown(vkUp) or KeyIsDown(vkSmallW) then    AngleH := AngleH - 3;
  if KeyIsDown(vkDown) or KeyIsDown(vkSmallS) then  AngleH := AngleH + 3;
  if KeyIsDown(vkLeft) or KeyIsDown(vkSmallA) then  AngleV := AngleV - 3;
  if KeyIsDown(vkRight) or KeyIsDown(vkSmallD) then AngleV := AngleV + 3;
  
  // contraints
  if AngleH < -80 then AngleH := -80;
  if AngleH > 80 then AngleH := 80;

  if KeyTrigger(vkEsc) then 
    raise ExGlutTerminate.Create('Esc pressed');

  // skybox
  glPushMatrix;
  glTranslatef(0, 0, 0);
  glRotatef(AngleH, 1, 0, 0);
  glRotatef(AngleV, 0, 1, 0);
  SkyBox.Show;
  glPopMatrix; 
    
  // refresh
  glutSwapBuffers;
  sleep(20);
end;

procedure OnIdle; cdecl;
begin
  glutPostRedisplay;
end;

begin
  InitOpenGl;
  Debug.Enable(dlInput);

  // skybox
  if ParamStr(1) <> '' then
    SkyBox := TSkyBox.Create(ParamStr(1),2000)
  else
    SkyBox := TSkyBox.Create('test',2000);

  // callbacks
  glutDisplayFunc(@OnDisplay);
  glutIdleFunc(@OnIdle);

  // main loop
  glutMainLoop;
end.
